<?php
require_once 'lib/controller.php';
require_once 'views/StandardView.php';
require_once 'db/AuthorisationDB.php';
require_once 'models/AuthorisationModel.php';
require_once 'models/EmailModel.php';
require_once 'db/MemberDB.php';
require_once 'views/ResetPasswordView.php';
require_once 'models/ResetPasswordModel.php';
$standardView = new StandardView($html, $_GET, $db);
$authDB = new AuthorisationDB($db);
$authModel = new AuthorisationModel($authDB);
$email = new EmailModel();
$memberDB = new MemberDB($db);
$view = new ResetPasswordView($html);
$model = new ResetPasswordModel($memberDB, $view, $authModel, $email);

$text = '';
$action = $helper->post('action');
$username = $helper->post('username');
if ($action === 'setPassword') {
    $resetPassword = $helper->post('resetPassword');
    $confirmPassword = $helper->post('confirmPassword');
    $authCode = $helper->post('auth');
    $returnPage = $helper->post('return');
    $text .= $model->confirmPassword($username, $resetPassword, $confirmPassword, $authCode, $returnPage);
} else if ($action === 'reset') {
    $text .= $model->resetPassword($username);
}else {
    $userId = intval($helper->get('userid'));
    if (!empty($userId)) {
        $authCode = $helper->get('auth');
        $returnPage = $helper->get('return');
        $text .= $model->userLogin($userId, $authCode, $returnPage);
    } else {
        $text .= $view->resetPasswordPage();
    }
}
$content = $view->render($text);
echo $standardView->render($content);
?>
